package com.xiyu.service.controller.admin.mailbox;
import com.xiyu.service.vo.mailbox.mailboxAccount.MailboxAccountGetTopAccountOutput;
import com.xiyu.service.vo.mailbox.mailboxAccount.MailboxAccountSingleGetOutput;
import com.xiyu.service.vo.mailbox.mailboxAccount.MailboxAccountPageQueryOutput;
import com.xiyu.service.vo.mailbox.mailboxAccount.MailboxAccountPageQueryInput;
import com.xiyu.service.vo.mailbox.mailboxAccount.MailboxAccountCreateInput;
import com.xiyu.service.vo.mailbox.mailboxAccount.MailboxAccountUpdateInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.service.mailbox.MailboxAccountService;

import java.util.List;

@Tag(name = "邮箱账号")
@RestController
@RequestMapping("/mailbox/mailbox-account")
@Validated
public class MailboxAccountController {

    @Resource
    private MailboxAccountService mailboxAccountService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询")
    @PreAuthorize("@ss.hasPermission('mailBox:mailAccount:query')")
    public CommonResult<PageResult<MailboxAccountPageQueryOutput>> pageQuery(@Valid MailboxAccountPageQueryInput inputVO) {
        return success(mailboxAccountService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增")
    @PreAuthorize("@ss.hasPermission('mailBox:mailAccount:create')")
    public CommonResult<Long> create(@Valid @RequestBody MailboxAccountCreateInput inputVO) {
        return success(mailboxAccountService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新")
    @PreAuthorize("@ss.hasPermission('mailBox:mailAccount:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody MailboxAccountUpdateInput inputVO) {
        return success(mailboxAccountService.update(inputVO));
    }

    @DeleteMapping("/deleted")
    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('mailBox:mailboxAccount:deleted')")
    @Parameter(name = "id", description = "邮箱账号主键ID", example = "")
    public CommonResult<Boolean> deleted(@RequestParam("id") Long id) {
        return success(mailboxAccountService.deleted(id));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个邮箱账号")
    @Parameter(name = "id", description = "邮箱账号主键ID", example = "")
    public CommonResult<MailboxAccountSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(mailboxAccountService.singleGet(id));
    }

    @GetMapping("/get-top-account")
    @Operation(summary = "获取前x的邮箱账号")
    @Parameter(name = "userId", description = "所属人ID", example = "")
    public CommonResult<List<MailboxAccountGetTopAccountOutput>> getTopAccount(@RequestParam("userId") Long userId) {
        return success(mailboxAccountService.getTopAccount(userId));
    }

}
